package com.szy.bigevent.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.szy.bigevent.mapper.CategoryMapper;
import com.szy.bigevent.pojo.Category;
import com.szy.bigevent.service.CategoryService;
import com.szy.bigevent.utils.ThreadLocalUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public Category selectById(Long id) {
        return categoryMapper.selectById(id);
    }

    @Override
    public PageInfo<Category> selectAll(Integer pageSize,Integer pageNum) {
        PageHelper.startPage(pageNum,pageSize);
        List<Category> list = categoryMapper.selectAll();
        PageInfo<Category> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public int deleteById(Long id) {
        return categoryMapper.deleteById(id);
    }

    @Override
    public int insertSelective(Category record) {
        //添加创建用户的ID
        final Map<String, Object> map = ThreadLocalUtil.get();
        final Integer id = (Integer) map.get("id");
        record.setCreateUser(id);

        return categoryMapper.insertSelective(record);
    }

    @Override
    public int updateByIdSelective(Category record) {
        return categoryMapper.updateByIdSelective(record);
    }

    @Override
    public List<Category> selectAll() {
        return categoryMapper.selectAll();
    }
}
